package com.atguigu.gulimall.product.service.impl;

import com.atguigu.gulimall.product.entity.PmsAttrAttrgroupRelation;
import com.atguigu.gulimall.product.dao.PmsAttrAttrgroupRelationMapper;
import com.atguigu.gulimall.product.service.AttrAttrgroupRelationService;
import com.atguigu.gulimall.product.vo.AttrGroupRelationVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<PmsAttrAttrgroupRelationMapper, PmsAttrAttrgroupRelation> implements AttrAttrgroupRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PmsAttrAttrgroupRelation> page = this.page(
                new Query<PmsAttrAttrgroupRelation>().getPage(params),
                new QueryWrapper<PmsAttrAttrgroupRelation>()
        );

        return new PageUtils(page);
    }

	@Override
	public void saveBatch(List<AttrGroupRelationVO> vos) {
		List<PmsAttrAttrgroupRelation> collect = vos.stream().map(item -> {
			PmsAttrAttrgroupRelation relationEntity = new PmsAttrAttrgroupRelation();
			BeanUtils.copyProperties(item, relationEntity);
			return relationEntity;
		}).collect(Collectors.toList());
		this.saveBatch(collect);
	}

}